package com.untour.im.server.handler;

import io.netty.channel.ChannelDuplexHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPromise;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class CustomExceptionHandler extends ChannelDuplexHandler {

    public static final CustomExceptionHandler INSTANCE = new CustomExceptionHandler();

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        log.error("CustomExceptionHandler inbound异常信息："+cause.getMessage());
    }
 
    @Override
    public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
        ctx.write(msg, promise.addListener( future -> {
            if (!future.isSuccess()){
                log.error("CustomExceptionHandler outbound异常信息："+future.cause().getMessage());
            }
        }));
    }
}